<?php 

function smarty_prefilter_micePreCompileAdmin($tpl_source,$smarty) 
{ 
	$tpl_source = str_replace("<?php die;?>","",$tpl_source);
	$tplpath=MICE_URL.MICE_TPL.'/admin/';
	/* 在头部加入版本信息 */
	$tpl_source = preg_replace('/<head>/i', "<head>\r\n<meta name=\"Generator\" content=\"" . MICE_VERSION . "\" />", $tpl_source);


	/* 修正css目录下css路径 */
	$tpl_source = preg_replace('/(<link\shref=["|\'])(?:\.\/|\.\.\/)?(css\/)?([a-z0-9A-Z_]+\.css["|\']\srel=["|\']stylesheet["|\']\stype=["|\']text\/css["|\'])/i','\1' . $tplpath . '\2\3', $tpl_source);

	/* 修正js目录下js的路径 */
	$tpl_source = preg_replace('/(<script\s(?:type|language)=["|\']text\/javascript["|\']\ssrc=["|\'])(?:\.\/|\.\.\/)?(js\/[a-z0-9A-Z_]+\.(?:js|vbs)["|\']><\/script>)/', '\1' . $tplpath . '\2', $tpl_source);

	/* 修正模板中对imgs目录下的链接 */
	$tpl_source = preg_replace('/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(imgs\/.*?["|\'])/is', '\1' . $tplpath . '\2', $tpl_source);
	$tpl_source = preg_replace('/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(imgs\/)/is', '\1' . $tplpath . '\2', $tpl_source);

	return $tpl_source;
} 

?> 
